package model

import (
	"gorm.io/gorm"
	"user_srv/global"
)

// 用户表
type User struct {
	gorm.Model
	Mobile   string `gorm:"column:mobile;type:char(11);not null;unique;comment:手机号"`
	Password string `gorm:"column:password;type:varchar(32);not null;comment:密码"`
	NickName string `gorm:"column:nick_name;type:varchar(50);not null;comment:昵称"`
	Sex      int    `gorm:"column:sex;type:int;not null;comment:性别"`
	Age      int    `gorm:"column:age;type:int;not null;comment:年龄"`
	Status   int    `gorm:"column:status;type:int;not null;comment:状态"`
}

// 用户注册
func (u *User) Register() (*User, error) {
	err := global.DB.Create(&u).Error
	return u, err
}

// 查询用户信息
func GetUserByMobile(mobile string) (u *User, err error) {
	err = global.DB.Where("mobile = ?", mobile).Find(&u).Error
	return
}
